package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrdersMapper {
    /**
     * 插入订单数据
     * @param orders
     */
    void insert(Orders orders);

    Orders getByNumber(String outTradeNo);

    /**
     * 更新订单状态
     * @param orders
     */
    void update(Orders orders);

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    OrderVO getById(Long id);
    @Delete("delete from orders where id = #{id}")
    void cancel(Long id);

    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 查询所有的订单
     * @return
     */
    @Select("select * from orders")
    List<Orders> getAllOrder();

    /**
     * 查询超时并且没有支付的顶动感
     * @param status
     * @param time
     */
    @Select("select * from orders where status = #{status} and order_time = #{time}")
    List<Orders> getStatusAndTime(Integer status, LocalDateTime time);
}
